package com.h2cloud.ThreadLocalTest.customExecutor;

/**
 * @Package: com.h2cloud.ThreadLocalTest.customExecutor
 * @ClassName: CurrentUser
 * @Author: h2cloud
 * @CreateTime: 2023/12/21 11:08 下午
 * @Description:
 */
import com.alibaba.ttl.TransmittableThreadLocal;
import lombok.Data;

/**
 * @author 向振华
 * @date 2023/01/12 10:40
 */
public class CurrentUserV2 {

	private CurrentUserV2() {
	}

	public static final TransmittableThreadLocal<UserInfo> CURRENT_USER = new TransmittableThreadLocal<>();

	public static UserInfo get() {
		return CURRENT_USER.get();
	}

	public static void set(UserInfo userInfo) {
		CURRENT_USER.set(userInfo);
	}

	public static void clear() {
		CURRENT_USER.remove();
	}

	@Data
	public static class UserInfo {
		private Long userId;
		private String name;
		private String mobile;
	}
}
